package routes

import (
	"net/http"

	"stock_app/logger"
	"stock_app/middlewares"

	"stock_app/controllers"

	"github.com/gin-contrib/pprof"
	"github.com/gin-gonic/gin"
)

func Setup() *gin.Engine {

	r := gin.New()
	r.Use(middlewares.Cors(), logger.GinLogger(), logger.GinRecovery(true))
	r.LoadHTMLFiles("./templates/index.html")
	r.Static("/static", "./static")
	r.GET("/", func(c *gin.Context) {
		c.HTML(http.StatusOK, "index.html", nil)
	})
	// v1 := r.Group("/api/v1")
	v1 := r.Group("/")
	{
		v1.POST("/job/save", controllers.HandleJobSave)
		v1.POST("/job/delete", controllers.HandleJobDelete)
		v1.GET("/job/list", controllers.HandleJobList)
		v1.POST("/job/kill", controllers.HandleJobKill)
		v1.GET("/job/log", controllers.HandleJobLog)
		v1.GET("worker/list", controllers.HandleWorkerList)
	}
	{
		v1.POST("/amount/list", controllers.HandleAmountList)
	}
	pprof.Register(r) // 注册pprof相关路由
	r.NoRoute(func(c *gin.Context) {
		c.JSON(http.StatusOK, gin.H{
			"msg": 404,
		})
	})

	return r
}
